package wsepForum.test.acceptance.bridge;

import wsepForum.test.acceptance.AcceptanceTests;



/**
 * An implementation of the interface which bridge the actions in it to our forum system
 * @author Oren Ben-Haim
 *
 */
public class ForumActionsProxyBridge implements IForumActions {


	private ForumActionsRealBridge realBridge;

	/*****************************
	 * CONSTRUCTOR               *
	 *****************************/
	public ForumActionsProxyBridge() {
		if (AcceptanceTests.REAL_BRIDGE_IMPLEMENTED) {
			this.realBridge = new ForumActionsRealBridge();
		}
	}

	/* (non-Javadoc)
	 * @see wsepForum.test.acceptance.bridge.IForumActions#actionTryToLoginWith(java.lang.String, java.lang.String)
	 */
	@Override
	public boolean actionTryToLoginWith(String username, String password) {
		if (AcceptanceTests.REAL_BRIDGE_IMPLEMENTED) {
			return this.realBridge.actionTryToLoginWith(username, password);
		}
		else {
			return (username.equals("user1") & password.equals("user1"));
		}
	}

	@Override
	public boolean actionTryToCreateSection(String sectionName, boolean isAdmin) {
		if (AcceptanceTests.REAL_BRIDGE_IMPLEMENTED) {
			System.err.println("%%%%%");
			return this.realBridge.actionTryToCreateSection(sectionName, isAdmin);
		}
		else {
			return isAdmin && !sectionName.isEmpty();
		}
	}

	@Override
	public boolean actionTryToCreateTopic(String topicName, String body, boolean isLoggedOn) {
		if (AcceptanceTests.REAL_BRIDGE_IMPLEMENTED) {
			return this.realBridge.actionTryToCreateTopic(topicName, body, isLoggedOn);
		}
		else {
			return isLoggedOn && !topicName.isEmpty();
		}
	}

	/* (non-Javadoc)
	 * @see wsepForum.test.acceptance.bridge.IForumActions#close()
	 */
	@Override
	public void closeBridge() {
		if (AcceptanceTests.REAL_BRIDGE_IMPLEMENTED) {
			this.realBridge.closeBridge();
		}
	}

	@Override
	public boolean actionTryToDeleteMessage(String subject, boolean isAuthor,
			boolean isAdmin) {
		if(isAdmin | isAuthor) return true;
		return false;
	}


	@Override
	public boolean actionTryToDeleteTopic(String subject, boolean isAuthor,
			boolean isAdmin) {
		if(isAdmin | isAuthor) return true;
		return false;
	}

	@Override
	public boolean changePassword(String username, String oldPass,
			String newPass) {
		return true;
	}

}
